import $api from '@/http/api.js'

export default {
    namespaced: true,
    state: {
        rows: [],
        pages: 0,
        total: 0
    },
    mutations: {
        SET_DATA(state, payload) {
            // console.log('payload',payload.length);
            state.rows = payload;
            // state.pages = payload.pages;
            state.total = payload.length;
        }
    },
    actions: {
        // 获取所有会员
        async getDataAsync(context, pageData) {
            const {data} = await $api.members.getAllMembers(pageData);
            if(data.meta.status == 200) {
                context.commit('SET_DATA', data.data)
            }
        },
        // 删除一个会员
        async deleteOneDataAsync(context, _id) {
            return await $api.members.delMember(_id);
        },
        // 修改一个会员
        async updateOneDataAsync(context, data) {
            return await $api.members.updateMemberToVip(data);
        },
        // 取消一个会员
        async cancleOneDataAsync(context, data) {
            return await $api.members.cancleMember(data);
        },
    }
}